package com.ict.bills.controller;

import com.ict.bills.domain.Bills;
import com.ict.bills.service.BillsService;
import com.ict.bills.utils.DataGridView;
import com.ict.bills.utils.ResultObj;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Author: Lizbeth9421
 * @Date: 2021/10/10/15:38
 */
@Controller
@RequestMapping("/bills")
public class BillsController {
    @Autowired
    private BillsService billsService;

    /**
     * 跳转到 list.html页面
     *
     * @return
     */
    @GetMapping("/toBillsList")
    public String toBillsList() {
        return "list";
    }

    @ResponseBody
    @GetMapping("/loadAllBills")
    public DataGridView loadAllBills( Bills bills){
        return billsService.loadAllBills(bills);
    }

    @ResponseBody
    @PostMapping("/addBills")
    public ResultObj addBills(Bills bill){
        try {
            bill.setBilltime(new Date());
            billsService.insertSelective(bill);
            return new ResultObj(200,"录入成功");
        }catch (Exception e){
           e.printStackTrace();
           return new ResultObj(-1, "录入失败");
        }
    }
}
